package org.arrow.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.Logger;

public class CmdTool {
	private static final Logger log = Logger.getLogger(CmdTool.class);
	public static boolean creatDir(String filePath) {
		boolean renBool = false;
		File file = new File(filePath);
		if (!file.exists())
			renBool = file.mkdirs();
		return renBool;
	}
	
	public static String GetPathByDate(String date){
		date=date.substring(0,13).replaceAll("-", "/");
		date=date.replaceAll(" ", "/");
//		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy/MM/dd/HH");
		return date;
	}
	
	public static String GetNumberByNowDate(){
		SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMddHHmm");
		return sdf2.format(new Date());
	}
	
	public static String RunCmd(String command) throws IOException {
		log.info(command);
		String reString = null;
		Process child = Runtime.getRuntime().exec(command);
		BufferedReader d = new BufferedReader(new InputStreamReader(child.getInputStream()));
		String c;
		while ((c = d.readLine()) != null) {
			if(reString == null)
				reString = c;
			else
				reString = reString + "\r\n" + c;
		}
		d.close();
		try {
			child.waitFor();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return reString;
	}
	
	
}
